package org.weishe.pagerank.hbase;

import java.io.IOException;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.util.StringUtils;

public class PreReducer extends Reducer<Text, Text, Text, Text> {

	private int sum = 0;

	@Override
	protected void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, Text, Text>.Context context)
			throws IOException, InterruptedException {
		if (key.toString().equals("count")) {
			for (Text t : values) {
				int count = Integer.parseInt(t.toString());
				sum = sum + count;
			}
			context.getConfiguration().setInt("totalcount", sum);
			// context.write(new Text(sum + ""), new Text());
		} else {
			// 原样输出
			for (Text t : values) {
				context.write(key, t);
			}
		}
	}

}
